/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ejb;

import javax.ejb.Stateless;
import javax.persistence.*;
import com.entity.Sorteos;

/**
 *
 * @author victor
 */
@Stateless
public class SorteosFachadaBean implements SorteosFachadaRemote, SorteosFachadaLocal {

    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
    @PersistenceContext
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

   public Sorteos UltimoSorteo(long idUltimo){

        Sorteos ultimo = null;
        Query miConsulta = em.createNamedQuery("Sorteos.Ultimo");
        miConsulta.setParameter("idUltimo", idUltimo);
        miConsulta.setMaxResults(1);
        try
        {
            ultimo = (Sorteos) miConsulta.getSingleResult();
        }catch ( NoResultException e ){}
         catch ( NonUniqueResultException e) {}
        return ultimo;
    }

   public long ultimoID() {

        Query miConsulta =  em.createNamedQuery("Sorteos.UltimoID");

        long exito = 0 ;
        try
        {
            exito = ((Long) miConsulta.getSingleResult()).intValue();

        }catch ( Exception e ){ exito = -1; return exito;}
         return exito;
    }
}
